<?php defined('BASEPATH') OR exit('No direct script access allowed');

/**
 * @package     Pages Module
 * @author      Matrix Infoline (infolinematrix@gmail.com
 * @copyright   (c) Matrix Infoline
 */

class Business extends Frontend_Controller
{

	public function __construct()
	{
		parent::__construct();
		$this->template->set_layout('member_layout');
		$this->template->set_partial('header', 'header/header');
		$this->template->set_partial('footer', 'footer/footer');
		$this->member_model->check_logedin();
		$this->load->model('term_model');
		$this->load->library('encrypt');
	}

	function plan(){
		$sql = "select id,name,description,price from membership where status = 51 order by (price) ASC";
		$result = $this->db->query($sql)->result();

		$data['title'] = "Choose Plan";
		$data['plan'] = $result;
		$this->template->build('plan',$data);
	}

	function add($planID=0){

		/* Added by Subha */
		$data['plan']['info'] = getPK('membership',$planID);


		$data['title'] = "Business Add";
		$data['mode'] = "VALIDATE";
		$data['region'] = $this->location_model->getLocation(0,9999);

		$this->template->set_breadcrumb('Home', base_url().seoUrl(location()));
		$this->template->set_breadcrumb('Member', 'member/dashboard');
		$this->template->set_breadcrumb('Business');
		$this->template->build('business',$data);

	}
	function edit($id){

		$memID = get_session('mem_id');
			
		$Csql = "Select * from post where id='$id' and mem_id='$memID'";
		$query = $this->db->query($Csql);
		$result = $query->result();
		if($result){
			$data['title'] = "Business Edit";

			$data['mode'] = "EDITBUSINESS";

			$data['business'] = getPK('post',$id);


			$data['cityID'] = $this->term_model->getTermValue($id,'city');

			$data['region'] = $this->location_model->getLocation(0,9999);

			// 		/var_dump($data['region']);die();
			$data['regionID'] = $this->term_model->getTermValue($id,'region');
			//	var_dump($data['regionID']);die();
			$data['cityname'] = $this->location_model->getLocation($data['regionID'],9999);

			$data['category'] = $this->category_model->getCetegory(0,9999);

			$array_cat = $this->term_model->getTermCategory($id,'category');



			$pid = $array_cat[0]->value;
			$pid = (int)$pid;

			//$data['subcategory'] = $this->category_model->getChild($pid,9999,FALSE);

			$data['subcategory'] = $this->category_model->getCetegory($array_cat[0]->value,9999);


			$data['catID'] = $pid;

			if(isset($array_cat[1]->value) && $array_cat[1]->value != 0 && $array_cat[1]->value != ''){
				$data['subcatID'] = $array_cat[1]->value;
			}else{
					
				$data['subcatID'] = 0;
			}



			if($data['subcatID']){

				$data['keyword'] = $this->category_model->getCetegory($data['subcatID'],9999);

			}else{
					
				$data['keyword'] = 0;
			}


			$data['keywordID'] = $this->term_model->getTermCategory($id,'keyword');

			/*
			 var_dump($data['keywordID']);die();

			$ar = $data['keyword'];
			$kr = array();
			foreach ($ar as $ar){
			$kr[] = $ar->id;
			}
			$data['kr'] = $kr;


			//print_r($kr); die();
			/*
			$ar = $kr;


			if (in_array(5085011, $ar)) {
			echo "Got mac";
			}else{
			echo "NOT";
			}

			//print_r($r);

			die("end");
			*/

			$data['post_id'] = $id;
			$data['mem_id'] = $memID;

		}else{
				
			$data['post_id'] = '';
			$data['mem_id'] = '';
			$data['business'] = '';
			$data['title'] = "Business Edit";
			$data['mode'] = "EDITBUSINESS";
			$data['business'] = '';
			$data['regionID'] = '';
			$data['cityID'] = '';
			$data['region'] = '';
			$data['cityname'] = '';
			$data['category'] = '';
				
				
		}
		$this->template->build('business',$data);
	}
	function add1()
	{

		$firstData = get_session('add1');

		if($firstData){

			$data['title'] = "Business Add";
			$data['mode'] = "NEW";
			$data['category'] = $this->category_model->getCetegory(0,9999);

			$this->template->set_breadcrumb('Home', base_url().seoUrl(location()));
			$this->template->set_breadcrumb('Member', 'member/dashboard');
			$this->template->set_breadcrumb('Business','member/business/add1');
			$this->template->set_breadcrumb('Add1');
		}else{
				
			redirect('member/business');
		}
		$this->template->build('business',$data);
	}

	function add2()
	{

		$seconDdata = get_session('add2');
		if($seconDdata){
			$data['first'] = get_session('add1');
			$data['second'] = get_session('add2');
			$data['title'] = "Business Add";

			$data['mode'] = "ADD";

			$this->template->set_breadcrumb('Home', base_url().seoUrl(location()));
			$this->template->set_breadcrumb('Member', 'member/dashboard');
			$this->template->set_breadcrumb('Business','member/business/add2');
			$this->template->set_breadcrumb('Add2');
		}else{
				
			redirect('member/business/add1');
		}
		$this->template->build('business',$data);
	}


	function submit(){




		$this->form_validation->set_rules('business_name','Business Name','xss_clean|required');
		$this->form_validation->set_rules('plan','Plan','xss_clean');
		$this->form_validation->set_rules('seourl','seourl','xss_clean');
		$this->form_validation->set_rules('region','Region','xss_clean|required');
		$this->form_validation->set_rules('city','City','xss_clean|required');
		$this->form_validation->set_rules('address','Address','xss_clean|required');
		//$this->form_validation->set_rules('long','long','xss_clean|required');
		//$this->form_validation->set_rules('lat','lat','xss_clean|required');
		if($this->form_validation->run() == FALSE){

			$msgs = "<div class='alert alert-warning'> All Fields are Mandatory</div>";
			$this->session->set_flashdata('message', $msgs);
			redirect('member/business');
			//$this->index();
		}


		$name = $_POST['business_name'];
		$plan = $_POST['plan'];
		$seourl = $_POST['seourl'];
		$region = $_POST['region'];
		$city = $_POST['city'];
		$address = $_POST['address'];
		$long = $_POST['long'];
		$lat = $_POST['lat'];



		$sql = "SELECT count(P.id) as no FROM post AS P
		INNER JOIN term AS T ON P.id  = T.post_id WHERE P.title = '$name' and P.address1 = '$address' and T.value = '$city'
		";

		$result = $this->db->query($sql)->result();

		if($result[0]->no != 0 ){

			$msgs = "<div class='alert alert-danger'> Data Already Exists</div>";
			$this->session->set_flashdata('message', $msgs);
			redirect('member/business');
		}
		else{

			$post_data1 = array(
					'name' => $name,
					'plan' => $plan,
					'slug' => $seourl,
					'region' => $region,
					'city' => $city,
					'address' => $address,
					'long' => $long,
					'lat' => $lat
			);

			write_session('add1',$post_data1);

			redirect('member/business/add1/');

		}

	}

	function submit1(){

		$this->form_validation->set_rules('perent_category','Parent Category','xss_clean|required');
		$this->form_validation->set_rules('sub_category','Sub Category','xss_clean');
		$this->form_validation->set_rules('zip_code','Zip Code','xss_clean|required');
		$this->form_validation->set_rules('fax_no','Fax No','xss_clean');
		$this->form_validation->set_rules('primary','Primary number','xss_clean|required');
		$this->form_validation->set_rules('secondary','Secodary Number','xss_clean');
		$this->form_validation->set_rules('toll_free','Toll Free','xss_clean');
		$this->form_validation->set_rules('business_email','Business Email','xss_clean|required');
		$this->form_validation->set_rules('website_url','Website Url','xss_clean');
		$this->form_validation->set_rules('contact_name','Contact Name','xss_clean');
		$this->form_validation->set_rules('contact_number','Contact Number','xss_clean');
		$this->form_validation->set_rules('contact_name_2','Contact Nmae 2','xss_clean');
		$this->form_validation->set_rules('contact_number_2','Contact Number 2','xss_clean');
		$this->form_validation->set_rules('description','Description','xss_clean|required');
		$this->form_validation->set_rules('services','Services','xss_clean|required');

		if($this->form_validation->run() == TRUE){


			$post_data2 = array(
					'category' => intval($this->input->post('perent_category')),
					'sub_category' => intval($this->input->post('sub_category')),
					'keyword' => $this->input->post('keyword[]'),
					'zip_code' => $this->input->post('zip_code'),
					'fax_no' => $this->input->post('fax_no'),
					'primary' => $this->input->post('primary'),
					'secondary' => $this->input->post('secondary'),
					'toll_free' => $this->input->post('toll_free'),
					'businesss_email' => $this->input->post('business_email'),
					'website_url' => $this->input->post('website_url'),
					'contact_name' => $this->input->post('contact_name'),
					'contact_number' => $this->input->post('contact_number'),
					'contact_name2' => $this->input->post('contact_name_2'),
					'contact_number2' => $this->input->post('contact_number_2'),
					'description' => $this->input->post('description'),
					'services' => $this->input->post('services'),
			);

			//var_dump($post_data2);die();

			write_session('add2',$post_data2);
			redirect('member/business/add2/');

		}else{
				
			$this->add1();
		}
	}

	function submit2()
	{

		$first = get_session('add1');


		$second = get_session('add2');

		//var_dump($first);die();

		$post_data3 = array(
				'mem_id' => get_session('mem_id'),
				'title' => $first['name'],
				'plan' => $first['plan'],
				'slug' => seoUrl($first['name']),
				'address1' => $this->input->post('address1'),
				'long' => $this->input->post('long'),
				'lat' => $this->input->post('lat'),
				'zip_code' => $second['zip_code'],
				'phone1' => $second['primary'],
				'phone2' => $second['secondary'],
				'fax' => $second['fax_no'],
				'toll_free' => $second['toll_free'],
				'email' => $second['businesss_email'],
				'website' => $second['website_url'],
				'contact_name' => $second['contact_name'],
				'contact_no' => $second['contact_number'],
				'description' => $second['description'],
				'services' => $second['services']

		);

		//	var_dump($post_data3);die();
		$this->db->insert('post',$post_data3);
		//--Get Latest ID--//
		$bid = $this->_getLastID();

		//--Save Category to Term --//
		$post_data4=array(
				'post_id' =>$bid,
				'term' => 'category',
				'caption' => 'Category',
				'value' => intval($second['category'])

		);
		$this->db->insert('term',$post_data4);

		//--Save Sub-Category to Term --//
		$post_data5=array(
				'post_id' =>$bid,
				'term' => 'category',
				'caption' => 'Category',
				'value' => intval($second['sub_category'])
		);
		$this->db->insert('term',$post_data5);

		//--Save Keyword to Term --//
		$keyword = $second['keyword'];
		foreach ($keyword as $key=>$value) {
			$post_data8= array(
					'post_id' =>$bid,
					'term' => 'keyword',
					'caption' => 'Keyword',
					'value' => $value
			);
			$this->db->insert('term',$post_data8);
		}
		//--Save City to Term --//
		$post_data6=array(
				'post_id' =>$bid,
				'term' => 'city',
				'caption' => 'City',
				'value' => intval($first['city'])
		);

		$this->db->insert('term',$post_data6);

		//--Save Region to Term --//
		$post_data7=array(
				'post_id' =>$bid,
				'term' => 'region',
				'caption' => 'Region',
				'value' => intval($first['region'])
		);

		$this->db->insert('term',$post_data7);

		//write_session('BusinessID',$bid);


		$businid = getPK('post',$bid);


		$name = getPK('membership',$businid['plan']);
		$name = $name['name'];

		$amt = getPK('membership',$businid['plan']);
		$amt = $amt['price'];

		$pID = getPK('membership',$businid['plan']);
		$pID = $pID['id'];


		if(isset($pID) && $amt!=0){
			//$amt=125.52;
			$u = 'member/payment/paypal/'.$pID.'/'.$name.'/'.$amt. '/' .$bid;
			redirect($u);
		}else{
			redirect('member/business/logo/'.$bid);

		}



	}
	//--Get Latest Id from Post Table--//
	function _getLastID(){
		$mem_id = intval(get_session('mem_id'));
		$sql = "Select max(id) as id from post where mem_id = $mem_id ";
		$result= $this->db->query($sql)->row();
		if ($result)
		{
			return $result->id;
		}

	}

	function logo($post_id=0)
	{
			
		$memID = get_session('mem_id');
			
		$Csql = "Select * from post where id='$post_id' and mem_id='$memID'";
		$query = $this->db->query($Csql);
		$result = $query->result();
		if($result){

			$sql="select logo from post where id=$post_id";

			$query = $this->db->query($sql);
			if ($query->num_rows() > 0) {
				$row = $query->row();
					
			}
			$data['logo']=$row->logo;

			$data['post_id'] = $post_id;
			$data['mem_id'] = $memID;
			$data['facilities'] = $this->member_model->membershipFacility($post_id,'logo' );
		}else{
			$data['post_id'] = '';
			$data['mem_id'] = '';
			$data['facilities'] = '';
		}
			
			
			



		$data['title'] = "Business Logo";

		$this->template->set_breadcrumb('Home', base_url().seoUrl(location()));
		$this->template->set_breadcrumb('Member', 'member/dashboard');
		$this->template->set_breadcrumb('Business','member/business/logo/'.$post_id);
		$this->template->set_breadcrumb('Logo');


		$this->template->build('logo',$data);
	}


	function upload_logo($post_id=0)
	{
		$post_id = $_POST['post_id'];

		$filevariable=array_keys($_FILES);
		$userfile=$filevariable[0];
		$image=$_FILES[$userfile];

		$vW='125';
		$vH='125';

		$imageData=array(
				'userfile'=>$userfile,
				'imagearray'=>$image,
				'imagepath'=>'./assets/img/data/logo/',
				'allowedtype'=>'jpg|png|gif|jpeg',
				'overwrite'=>'true',
				'removespace'=>'true',
				'customefilename'=>'',     		//do not use extension if not need leave blank
				'namewithtime'=>'yes', 			//time(image_121326.jpg)at last of file name if not need leave blank
				'separator'=>'-', 				//format - image_121326.jpg (.)not allowed, if not require leave blank
				'prefix'=>'yp_',				//format my_image_121326.jpg , if not require leave blank
				'errmessage'=>'',               // If blank default message will shown
				'sucessmessage'=>'',            // If blank default message will shown
				'createthumb'=>'yes',
				'thumbwidth'=>$vW,
				'thumbheight'=>$vH,
				'thumbpath'=>'' 				// Dont write thumb folder name in path

		);

		$uploadData=$this->member_model->upload($imageData);


		$id = $this->input->post('post_id');

		$data=array(

				//'id'=>$listing_id,
				'logo'=>$uploadData['data'],

		);

		if ($uploadData['data']  == TRUE ) {


			$logo = $this->member_model->post_logo($post_id);

			if ($logo->logo != 'no-logo.png') {
				$f = BASEPATH.'../assets/img/data/logo/' . $logo->logo;
				unlink($f);
			}
			$this->db->where('id', $id);
			$this->db->update('post',$data);
			$msg = "<div class='alert alert-success'> Logo Uploded Sucessfully!... </div>";
			$this->session->set_flashdata('message', $msg);
			redirect('member/business/logo/'.$post_id);
		} else {
			$msg = "<div class='alert alert-success'> Invalid...! </div>";
			$this->session->set_flashdata('message', $msg);
			redirect('member/business/logo/'.$post_id);
			exit();

		}
	}


	function photo($post_id=0)
	{

		$data['mode'] = "IMG";
		$data['title'] = "Business Photo";


		$memID = get_session('mem_id');

		$Csql ="Select * from post where id='$post_id' and mem_id='$memID'";
		$query = $this->db->query($Csql);
		$result = $query->result();
		if($result){

				
			$data['post_id'] = $post_id;
			$data['mem_id'] = $memID;
			$data['photos'] = $this->member_model->getGallerydata($post_id,'photo');
			$data['facilities'] = $this->member_model->membershipFacility($post_id,'photo' );
			$data['fac_limit'] = $this->member_model->membershipFacility($post_id,'photo_limit' );

			$data['total'] = count($data['photos']);
				
				
				
		}else{
				
			$data['post_id'] = '';
			$data['mem_id'] = '';
			$data['photos'] = '';
			$data['facilities'] = '';
			$data['fac_limit'] = '';
			$data['total'] = '';
		}

		$this->template->set_breadcrumb('Home', base_url().seoUrl(location()));
		$this->template->set_breadcrumb('Member', 'member/dashboard');
		$this->template->set_breadcrumb('Business','member/business/photo/'.$post_id);
		$this->template->set_breadcrumb('Photo');

		$this->template->build('gallery',$data);


	}

	function uploader()
	{
		$post_id = $this->input->post('post_id');
		for($i=0 ; $i<count($_FILES["gallery"]["name"]) ; $i++){
			if($_FILES["gallery"]["name"][$i] != ''){ // don't insert if file name empty
				//$dataType = mysql_real_escape_string($_POST["dataType"][$i]);
				$title = mysql_real_escape_string($_POST["gallery_title"][$i]);

				$fileData = pathinfo($_FILES["gallery"]["name"][$i]);

				$post_id = $this->input->post('post_id');
				$term = 'photo';
				$caption = 'Photo';
				$photo_limit = $this->input->post('fac_limit');

				$fileName = uniqid() . '.' . $fileData['extension'];
				$target_path = "assets/img/data/photo/" . $fileName;

				while(file_exists($target_path)){
					$fileName = uniqid() . '.' . $fileData['extension'];
					$target_path = "assets/img/data/photo/" . $fileName;
				}

				if (move_uploaded_file($_FILES["gallery"]["tmp_name"][$i], $target_path)){    // The file is in the images/gallery folder.
					// Insert record into database by executing the following query:



					$sql="INSERT INTO gallery (title, value, post_id, term, caption) "."VALUES('$title','$fileName','$post_id','$term','$caption')";
					$this->db->query($sql);


					//redirect('member/business/photo/'.$post_id);

					//echo "The image {$_FILES['gallery']['name'][$i]} was successfully uploaded and added to the gallery<br />

					//<a href='index.php'>Add another image</a><br />";

					//	redirect('member/business/photo/'.$post_id);
					$this->photo($post_id);
				}
				else
				{
					//	redirect('member/business/photo/'.$post_id);
				}
			}else{
				redirect('member/business/photo/'.$post_id);
			}
		}
		//
	}

	function delete_photo() {
		
			$post_id = $_GET['post_id'];
			$photo_id = $_GET['photo_id'];
			$image_file =$_GET['image'];
		
			$this->member_model->delete_photo($photo_id,$image_file);
			redirect('member/business/photo/'.$post_id);
		
	}

	function video($post_id=0){


		$data['mode'] = "VIDEO";

		$data['title'] = "Business Video";
			
		$memID = get_session('mem_id');

		$Csql ="Select * from post where id='$post_id' and mem_id='$memID'";
		$query = $this->db->query($Csql);
		$result = $query->result();
		if($result){

			$data['post_id'] = $post_id;
			$data['mem_id'] = $memID;
			$data['videos'] = $this->member_model->getGallerydata($post_id,'video');
			$data['facilities'] = $this->member_model->membershipFacility($post_id,'video' );
		}else{

			$data['post_id'] = '';
			$data['mem_id'] = '';
			$data['videos'] = '';
			$data['facilities'] = '';
		}

		$this->template->set_breadcrumb('Home', base_url().seoUrl(location()));
		$this->template->set_breadcrumb('Member', 'member/dashbaord');
		$this->template->set_breadcrumb('Business','member/business/video/'.$post_id);
		$this->template->set_breadcrumb('Video');
			
		$this->template->build('gallery',$data);
	}





	function upload_video($post_id=0){

		$this->form_validation->set_rules('video','Video','required|xss_clean');
		$post_id = $this->input->post('post_id');
		$video = $this->input->post('video');
		$len=strlen($video);
		$pos=strrpos($video, '=');
		$urlid= substr($video,$pos+1);

		if($this->form_validation->run() == TRUE){

			$post_data = array(

					'post_id' => $post_id,
					'term' => 'video',
					'value' => $urlid,
					'caption' => 'Video'

			);

			//	var_dump($post_data);die();

			$sql = "Select * from gallery where post_id ='$post_id' and term='video' limit 1 ";
			$result = $this->db->query($sql)->row();

			if(count($result)==0){
				$this->db->insert('gallery',$post_data);
				$msg = "<div class='alert alert-success'> Video Uploded Sucessfully!... </div>";
				$this->session->set_flashdata('message', $msg);
				redirect('member/business/video/'.$post_id);
			}else{
				$msg = "<div class='alert alert-warning'> Allready Exist...! </div>";
				$this->session->set_flashdata('message', $msg);
				redirect('member/business/video/'.$post_id);
				exit();
			}
				

		}else{
			$msg = "<div class='alert alert-warning'> Invalid...! </div>";
			$this->session->set_flashdata('message', $msg);
			redirect('member/business/video/'.$post_id);
			exit();

		}
	}

	function update_business($id=0){

		$id = $this->input->post('post_id');

		$this->form_validation->set_rules('business_name', 'Business Name', 'trim|required|xss_clean');

		$this->form_validation->set_rules('category', 'Parent Category', 'trim|required');
		$this->form_validation->set_rules('sub_category', 'Sub-Category', 'trim');
		$this->form_validation->set_rules('keyword[]', 'Keyword', 'trim');

		$this->form_validation->set_rules('region', 'Region', 'trim|required');
		$this->form_validation->set_rules('city', 'City', 'trim|required');

		$this->form_validation->set_rules('address1', 'Address', 'trim|required|xss_clean');
		$this->form_validation->set_rules('zip_code', 'Zip Code', 'trim|required|numeric');
		$this->form_validation->set_rules('fax_no', 'Fax No', 'trim|xss_clean');
		$this->form_validation->set_rules('primary','Phone No', 'trim|required');
		$this->form_validation->set_rules('secondary','Phone No','trim');
		$this->form_validation->set_rules('toll_free', 'Toll Free', 'trim|xss_clean');
		$this->form_validation->set_rules('business_email', 'Business Email', 'trim|required|valid_email');

		$this->form_validation->set_rules('website_url', 'Website Url', 'trim|xss_clean');
		$this->form_validation->set_rules('contact_name', 'Contact Person(1)', 'trim|xss_clean');
		$this->form_validation->set_rules('contact_number', 'Contact Person(1)', 'trim|xss_clean');
		$this->form_validation->set_rules('contact_name_2', 'Contact Person(2)', 'trim|xss_clean');
		$this->form_validation->set_rules('contact_number_2', 'Contact Person(2)', 'trim|xss_clean');
		$this->form_validation->set_rules('description','About Business','trim|xss_clean|required');
		$this->form_validation->set_rules('services','Product and Services','trim|xss_clean|required');
			


		if ($this->form_validation->run() == TRUE) {
			$post_data = array(
					'mem_id' =>get_session('mem_id'),

					'title' => trim($this->input->post('business_name')),
					'slug' => seoUrl($this->input->post('business_name')),
					'zip_code' => intval($this->input->post('zip_code')),
					'address1' => $this->input->post('address1'),
					'fax' => $this->input->post('fax_no'),
					'phone1' => $this->input->post('primary'),
					'phone2' => $this->input->post('secondary'),
					'toll_free' => $this->input->post('toll_free'),
					'email' => $this->input->post('business_email'),
					'website' => $this->input->post('website_url'),
					'contact_name' => $this->input->post('contact_name'),
					'contact_no' => $this->input->post('contact_number'),
					'contact_name' => $this->input->post('contact_name_2'),
					'contact_no2' => $this->input->post('contact_number_2'),
					'description' => $this->input->post('description'),
					'services' => $this->input->post('services'),
					'lat' => $this->input->post('lat'),
					'long' => $this->input->post('long'),
			);

			//var_dump($business_data);die();

			$this->db->where('id', $id);
			$this->db->update('post', $post_data);

			//--Delete All Existing--//
			$sql = "Delete from term where post_id=$id";
			$this->db->query($sql);

			//--Insert Category in Term Table--//

			$term_data1=array(
					'post_id' =>$id,
					'term' => 'category',
					'caption' => 'Category',
					'value' => intval($_POST['category'])
			);
			$this->db->insert('term',$term_data1);

			//--Insert Sub-Category in Term Table --//
			$term_data2=array(
					'post_id' =>$id,
					'term' => 'category',
					'caption' => 'Category',
					'value' => intval($_POST['sub_category'])
			);
			$this->db->insert('term',$term_data2);

			//--Insert  Keyword in Term Table--//

			$keyword = $_POST['keyword'];
			foreach ($keyword as $key=>$value) {
					
				$term3_data= array(
						'post_id' =>$id,
						'term' => 'keyword',
						'caption' => 'Keyword',
						'value' => $value,
				);
					
					
				$this->db->insert('term',$term3_data);
			}
				
			//--Insert City in Term Table --//
			$term_data4=array(
					'post_id' =>$id,
					'term' => 'city',
					'caption' => 'City',
					'value' => intval($_POST['city'])
			);
				
				
			$this->db->insert('term',$term_data4);
				
				
			//--Insert Region in Term Table --//
			$term_data5=array(
					'post_id' =>$id,
					'term' => 'region',
					'caption' => 'Region',
					'value' => intval($_POST['region'])
			);
			$this->db->insert('term',$term_data5);
				
			$msgs = "<div class='alert alert-info'> Business Update Successfully</div>";
			$this->session->set_flashdata('message', $msgs);
			redirect('member/business/edit/'. $id);
		}
		else{
			$this->edit($id);
		}



	}



	function change($post_id){

		$data['businessplan'] = getPK('post',$post_id);

		$data['mode'] = "CHANGE";


		$sql = "select id,name,description,price from membership where status = 51 and price != '0' order by (price) ASC";
		$result = $this->db->query($sql)->result();

		$data['title'] = "Update Your Business : ". $data['businessplan']['title'];
		$data['plan'] = $result;

		$this->template->build('business',$data);

	}

}

